package com.xing.email.controller;

import com.xing.Utils.Result;
import com.xing.email.dto.EmailDTO;
import com.xing.email.service.EmailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;
import java.io.File;

@RestController
@RequestMapping("email")
@CrossOrigin
@Tag(name = "发送邮件服务")
public class EmailController {

    @Autowired
    private EmailService emailService;

    @Value("${spring.mail.username}")
    private String email;


    @Operation(summary = "发送邮件")
    @PostMapping("/send-html-email")
    public Result sendHtmlEmail(@RequestBody EmailDTO dto) throws MessagingException {
        emailService.sendHtmlEmail(dto.getEmail(), "HTML 邮件", dto.getContent(), null);
        return new Result().ok("HTML邮件已发送");

    }
}
